import unittest, requests


class Weidu(unittest.TestCase):
    def setUp(self) -> None:
        print('start case')

    def tearDown(self) -> None:
        print('end case')

    # 登录
    userId = None
    sessionId = None
    phone = None

    def test_Weidu_01(self):
        r1 = requests.post(url='http://10.59.9.18/health/user/v1/login',
                           params={"email": "3500186206@qq.com",
                                   "pwd": "lZjdXyj15cOhn1a0yJKsW7o+fw/ogBDzn6CcyPSJUVIMmCPtCs+zuPwh7IZkXZiRhJvvjdIz9D2z1jkMOtD/36ddaLFMtQd9xIk0jAaDP1TH/lEHvvUPwot6asMGMGkH9EgBPT+4eaYC77BGQBPOASweQZE5KDF8BeN/c0sLfSw="})

        print(r1.json())
        # 提取userId sessionId
        Weidu.userId = str(r1.json()['result']['userId'])
        Weidu.sessionId = str(r1.json()['result']['sessionId'])
        print(Weidu.userId)
        print(Weidu.sessionId)

    # 查询问诊医生列表
    doctorId = None

    def test_Weidu_02(self):
        r2 = requests.get(url='http://10.59.9.18/health/user/inquiry/v1/findDoctorList',
                          params={"deptId": 2, 'condition': 2, 'sortBy': 1, 'page': 1, 'count': 5})
        print(r2.json())
        # 提取 doctorId
        Weidu.doctorId = r2.json()['result'][0]['doctorId']
        print('doctorId：', Weidu.doctorId)

    # 咨询医生

    def test_Weidu_03(self):
        r3 = requests.put(url='http://10.59.9.18/health/user/inquiry/verify/v1/consultDoctor',
                          headers={'userId': str(Weidu.userId), 'sessionId': str(Weidu.sessionId)},
                          params={'doctorId': Weidu.doctorId})
        print(r3.json())

    # 查看历史问诊
    recordId = None

    def test_Weidu_04(self):
        r4 = requests.get(url='http://10.59.9.18/health/user/inquiry/verify/v1/findHistoryInquiryRecord',
                          headers={'userId': str(Weidu.userId), 'sessionId': str(Weidu.sessionId)},
                          params={'page': 1, 'count': 5, 'doctorId': Weidu.doctorId}
                          )
        print(r4.json())

        # 提取 问诊id
        Weidu.recordId = r4.json()['result'][0]['recordId']
        print(Weidu.recordId)

    # 患者 - 发送消息（文本消息）
    message = None
    def test_Weidu_05(self):
        r5 = requests.post(url='http://10.59.9.18/health/user/inquiry/verify/v1/pushMessage',
                          headers={'userId': str(Weidu.userId), 'sessionId': str(Weidu.sessionId)},
                           data={'inquiryId':str(Weidu.recordId),'content':'我是文本消息',
                                 'type':1,'doctorId':Weidu.doctorId})
        print(r5.json())
        # 断言 推送成功  提取 message
        Weidu.message = r5.json()['message']
        self.assertEqual('推送成功',Weidu.message)

    # 结束问诊
    messag2=None
    def test_Weidu_06(self):
        r6 = requests.put(url='http://10.59.9.18/health/user/inquiry/verify/v1/endInquiry',
                           headers={'userId': str(Weidu.userId), 'sessionId': str(Weidu.sessionId)},
                           data={'recordId': str(Weidu.recordId)})
        print(r6.json())
        # 断言 推送成功  提取 message
        Weidu.message = r6.json()['message']
        self.assertIn('该问诊已结束,不能重复操作', Weidu.message)


if __name__ == '__main__':
    # 第一种方式
    unittest.main()
